#include "bd.h"

void main(void)
{
  int i;

//mysql
  BDPair params[] =
  {
    {"host","localhost"},
    {"dbname","kartfacil"},
    {"port","3306"},
    {"user","root"},
    {"password",""},
    {"sslmode","prefer"},
    {"connect_timeout","10"},
    {0,0}
  };
  char *queries[] = 
  {
    "select * from pista where col1=?"
    "select * from pista",
    "select * from pilotos",
  };
  char *values[] = {"V1"};

//postgres
/*
  BDPair params[] =
  {
    {"host","localhost"},
    {"dbname","kartfacil"},
    {"port","5432"},
    {"user","postgres"},
    {"password","facil123"},
    {"sslmode","prefer"},
    {"connect_timeout","10"},
    {0,0}
  };
  char *queries[] = 
  {
    "select * from pista where id=$1"
    "select * from pista",
    "select * from piloto",
  };
  char *values[] = {"1"};
*/

  BDConnection *conn = bdConnect(params);

  if(conn)
  {
    for(i=0; i<3; i++)
    {
      BDResult *res;
      if(i==0) res = bdExecQuery(conn,queries[i],values,1);
      else res = bdExecQuery(conn,queries[i],0,0);
      if(res)
      {
        printf("aqui %d %d\n",res->rows,res->cols);
        while(bdNextRow(res))
        {
          int i=0;
          for(i=0;i<res->cols;i++)
          {
            printf("%s=%s ",bdResultColName(res,i),bdResultVal(res,i));
          }
          printf("\n");
        }
        bdFreeResult(res);
      }
    }
  }
}
